//
//  BBNavigationController.swift
//  BaoKanSwift
//
//  Created by uncle-R on 16/6/9.
//  Copyright © 2016年 uncle-R. All rights reserved.
//

import UIKit

class BBNavigationController: UINavigationController {

    override func viewDidLoad() {
        super.viewDidLoad()

        navigationBar.barStyle = UIBarStyle.Black
        navigationBar.barTintColor = UIColor.colorWithRGB(244, g: 244, b: 244) //导航栏背景颜色
        navigationBar.translucent = false //左边显示返回的属性.
        //去除导航栏的默认背景
        navigationBar.setBackgroundImage(UIImage(), forBarMetrics: UIBarMetrics.Default)
         navigationBar.shadowImage = UIImage()
        navigationBar.titleTextAttributes = [
            NSForegroundColorAttributeName : UIColor(red:0.173,  green:0.173,  blue:0.173, alpha:1),
            NSFontAttributeName : UIFont.systemFontOfSize(18)
        ]
    }
    
    override func pushViewController(viewController: UIViewController, animated: Bool) {
        
        if viewControllers.count > 0 {
            viewController.hidesBottomBarWhenPushed = true
            // 压入栈后创建返回按钮
            viewController.navigationItem.leftBarButtonItem = UIBarButtonItem(
                image: UIImage(named: "top_navigation_back")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal),
                style: UIBarButtonItemStyle.Done,
                target: self,
                action: #selector(backClick)
            )
        }else{
            viewController.hidesBottomBarWhenPushed = false
        }
        super.pushViewController(viewController, animated: animated)
        
    }

    func backClick() {
        popViewControllerAnimated(true)
    }
  
}
